package com.utils.PayUtils.wxpay;


import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @Author chihaojie
 * @Description 微信pay配置对象
 * @date 2019/4/23   17:47
 **/

public class WXPayConfigBean extends WXPayConfig {

    public static final String KEY="182006250b4c09247ec02edce69f6a2f";

    //公众账号ID
    public static final String APP_ID="wxc01af68939f4a898";
    //商户号 --微信支付分配的商户号
    public static final String MCH_ID="1540285921";

    public static final String certificatePath="/data/publish/wx_cert/apiclient_cert.p12";

    public static final String certificateLocalPath="D:\\data\\1540285921_20190619_cert\\apiclient_cert.p12";


    @Override
    String getAppID() {
        return APP_ID;
    }

    @Override
    String getMchID() {
        return MCH_ID;
    }

    @Override
    String getKey() {
        return KEY;
    }

    @Override
    InputStream getCertStream() {
        try{
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("apiclient_cert.p12");
            Resource resource = new ClassPathResource("apiclient_cert.p12");
            File sourceFile =  resource.getFile();
            FileInputStream instream = new FileInputStream(sourceFile);
            return  instream;
        }catch (Exception e){
            e.printStackTrace();
        }

        return null;
    }

    @Override
    IWXPayDomain getWXPayDomain() {
      return  new IWXPayDomain(){
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                DomainInfo domainInfo=new DomainInfo(WXPayConfig.DOMAIN_API,true);
                return domainInfo;
            }
        };
    }


    public static String getKEY() {
        return KEY;
    }
}
